/**
 * 
 */
package com.holystone.orca.sys.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.holystone.orca.base.service.impl.BaseServiceImpl;
import com.holystone.orca.common.PageData;
import com.holystone.orca.sys.mybatis.dao.SysRoleMapper;
import com.holystone.orca.sys.mybatis.model.SysRole;
import com.holystone.orca.sys.service.ISysRoleService;

@Service(value="RoleService")
@Transactional
public class SysRoleServiceImpl extends BaseServiceImpl<SysRole> implements ISysRoleService{
	@Autowired
	private SysRoleMapper sysRoleMapper;

	@Override
	public List<SysRole> getRoleList() {
		List<SysRole> list=sysRoleMapper.getRoleList();
		return list;
	}

	@Override
	public int getStaffRoleByPersonId(Map<String, String> map) {
		if(sysRoleMapper.getStaffRoleList(map).size()==0){
			return 1;
		}else{
			return sysRoleMapper.getStaffRoleList(map).get(0).getRoleId();
		}
		
	}

	@Override
	public PageData pagingSysRole(int iPageNo, int iPageSize,
			String orderField, String roleName) throws Exception {
			Map<Object, String> map=new HashMap<Object, String>();
			map.put("roleName", roleName);
			
	        //分页查询
	        PageHelper.startPage(iPageNo, iPageSize);
	        PageInfo<SysRole> pageInfo = new PageInfo<SysRole>(sysRoleMapper.selectRole(map));
			PageData pageData =  new PageData();
			pageData.setPageList(pageInfo.getList());
			pageData.setTotalCount(pageInfo.getTotal());
			pageData.setPageSize(pageInfo.getPageSize());
			pageData.setPageNo(pageInfo.getPageNum());
			pageData.setTotalPage(pageInfo.getPages());
			return pageData;
		}

	@Override
	public boolean insertRole(SysRole sysRole) {
		int result=sysRoleMapper.insertRole(sysRole);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public SysRole selectRoleByRoleId(int roleId) {
		List<SysRole> roleList=sysRoleMapper.selectRoleByRoleId(roleId);
		return roleList.get(0);
	}

	@Override
	public boolean updateRoleByRoleId(SysRole sysRole) {
		int result=sysRoleMapper.updateRoleByRoleId(sysRole);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean delRoleByRoleId(int roleId) {
		int result=sysRoleMapper.delRoleByRoleId(roleId);
		if(result==1){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public boolean delSelectRole(List<Integer> list) throws Exception {
		int result=sysRoleMapper.delSelectRole(list);
		if(result==list.size()){
			return true;
		}else{
			return false;
		}
	}

	@Override
	public List<SysRole> selectRole(Map<Object, String> map) throws Exception {
		List<SysRole> sysRoleList = sysRoleMapper.selectRole(map);
		return sysRoleList;
	}
	

}
